/**
 * 文件名    ： MyEmbeddedServletContainerFactory.java
 * 版权       : XX科技有限公司。
 * 描述       : <描述>
 * 修改时间：2018年11月24日
 * 修改内容：<修改内容>
 */
package com.example.demo.application.common;

import org.apache.catalina.connector.Connector;  
import org.apache.coyote.http11.Http11NioProtocol;
import org.springframework.boot.web.embedded.tomcat.TomcatConnectorCustomizer;
import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
import org.springframework.boot.web.servlet.server.ConfigurableServletWebServerFactory;
import org.springframework.context.annotation.Bean;  
import org.springframework.context.annotation.Configuration;

  
@Configuration  
public class MyEmbeddedServletContainerFactory  
{

    @Bean
    public ConfigurableServletWebServerFactory webServerFactory() {
        TomcatServletWebServerFactory tomcatFactory = new TomcatServletWebServerFactory();
        tomcatFactory.addConnectorCustomizers(new MyTomcatConnectorCustomizer());
//        tomcatFactory.setPort(8005);
//        tomcatFactory.setContextPath("");
        return tomcatFactory;
    }

}  
class MyTomcatConnectorCustomizer implements TomcatConnectorCustomizer  
{  
    public void customize(Connector connector)  
    {  
        Http11NioProtocol protocol = (Http11NioProtocol) connector.getProtocolHandler();  
        //设置最大连接数  
        protocol.setMaxConnections(2000);  
        //设置最大线程数  
        protocol.setMaxThreads(1000);  
        protocol.setConnectionTimeout(3000);  
    }  
}